<?php
 Session_Start () ;
 Include ("../../include/garennes.cfg") ;
 Include ("../../include/init.php") ;
 Include ("../include/config.inc") ;
 verif_droits ($droit_courant, $_SESSION ["code"]) ;
 
 $requete = var_courante ("requete", 0, null) ;
 $id_discipline = var_courante ("id_discipline", 0, null) ;
 $millesime = millesime (0) ;
 
 If (IsSet ($requete))
  {
   Switch ($requete)
    {
     // Insertion d'une phrase specifique
     Case 0 : $type_moyenne = champ_disc_type_moyenne_parid ($id_discipline) ;
              If ($type_moyenne == 1)
	       {
	        $min = var_courante ("min", 0, 0) ;
                $max = var_courante ("max", 0, 100) ;
	       }
	      Else
	       {
                $min = var_courante ("min", 0, 0) ;
                $max = var_courante ("max", 0, $note_par_defaut) ;
	       }
              $condition_1 = var_courante ("condition_1", 0, 0) ;
              $condition_2 = var_courante ("condition_2", 0, 0) ;
	      $phrase = var_courante ("phrase", 0, "") ;
              $ok = SQL_commande ("INSERT INTO phrases_specifiques (id_discipline,min,max,condition_1,condition_2,phrase)
	                           VALUES ('".$id_discipline."','".$min."','".$max."','".$condition_1."','".$condition_2."','".$phrase."')", $id_sql) ;
	      $requete = 0 ;
              Break ;
     // Effacement
     Case 1 : $id_phrase_specifique = var_courante ("id_phrase_specifique", 0, 0) ;
              $resultat = SQL_commande ("DELETE FROM phrases_specifiques WHERE id_phrase_specifique='".$id_phrase_specifique."' LIMIT 1", $id_sql) ;
              $modif = SQL_tableau_associatif ($resultat, "") ;
	      $requete = 0 ;
              Break ; 
     // Debut de modification
     Case 2 : $id_phrase_specifique = var_courante ("id_phrase_specifique", 0, 0) ;
              $resultat = SQL_commande ("SELECT * FROM phrases_specifiques WHERE id_phrase_specifique='".$id_phrase_specifique."'", $id_sql) ;
              $modif = SQL_tableau_associatif ($resultat, "") ;
	      $requete = 3 ;
              Break ;
     // Fin de modification
     Case 3 : $id_phrase_specifique = var_courante ("id_phrase_specifique", 0, 0) ;
              $type_moyenne = champ_disc_type_moyenne_parid ($id_discipline) ;
              If ($type_moyenne == 1)
	       {
	        $min = var_courante ("min", 0, 0) ;
                $max = var_courante ("max", 0, 100) ;
	       }
	      Else
	       {
                $min = var_courante ("min", 0, 0) ;
                $max = var_courante ("max", 0, $note_par_defaut) ;
	       }
              $condition_1 = var_courante ("condition_1", 0, 0) ;
              $condition_2 = var_courante ("condition_2", 0, 0) ;
	      $phrase = var_courante ("phrase", 0, "") ;
              $ok = SQL_commande ("UPDATE phrases_specifiques SET min='".$min."',max='".$max."',condition_1='".$condition_1."',condition_2='".$condition_2."',code='".$code_disc."',millesime='".$millesime."',phrase='".$phrase."' WHERE id_phrase_specifique='".$id_phrase_specifique."' LIMIT 1", $id_sql) ;
	      $requete = 0 ;
              Break ;
    }
  }
 Else
  { $requete = 0 ; }
 
 If (!IsSet ($modif))
  {
   $modif ["id_phrase_specifique"] = $modif ["min"] = $modif ["max"] = $modif ["condition_1"] = $modif ["condition_2"] = 0 ;
   $modif ["phrase"] = "" ;
  }
 
 $resultats = SQL_commande ("SELECT * FROM menus WHERE numero='".$droit_courant."' AND ordre='0' LIMIT 1", $id_sql) ;
 $l = SQL_tableau_associatif ($resultats, "") ; 
 Echo "<html><head>" ;
 entete_html ("Garennes", "travail", 1) ;
 Echo styles ("none", "none", "none", $l ["lien"], "none") ;
 //Include ("./gestion_disciplines.js") ;
 Echo "</head>" ;
 
 Echo "<body background=\"../images/fond.png\" text=\"#000000\" onContextMenu=\"return false\">" ;
 If (IsSet ($id_discipline) And ($id_discipline > 0))
  {
   Echo "<center><font color=\"#0000ff\"><b>Param&eacute;trage&nbsp;de&nbsp;la&nbsp;discipline&nbsp;".nom_disc_long_parid ($id_discipline).".</b></font></center>" ;
   Echo "<table align=\"center\" border=\"0\" cellspacing=\"1\" cellpadding=\"0\" style=\"border-collapse:collapse\">" ;
   Echo "<tr><td><table align=\"center\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"".$l ["couleur_fond"]."\" style=\"border:1px solid #000000;border-collapse:collapse\">" ;
   Echo "<tr><td align=\"center\" bgcolor=\"".$l ["lien"]."\"><font size=\"".$l ["titre"]."\">&nbsp;<b>D&eacute;finition&nbsp;des&nbsp;appr&eacute;ciations&nbsp;en&nbsp;fonction&nbsp;des&nbsp;r&eacute;sultats.</b>&nbsp;</font></td></tr>" ;
   Echo "<tr><td>" ;
   Echo "<table width=\"100%\" border=\"0\" style=\"border-collapse:collapse\">" ;
   $resultats = SQL_commande ("SELECT * FROM phrases_specifiques WHERE id_discipline='".$id_discipline."' ORDER BY min", $id_sql) ;
   $nbr_champs = SQL_nbr_lignes ($resultats) ;
   If ($nbr_champs > 0)
    {
     $type_moyenne = champ_disc_type_moyenne_parid ($id_discipline) ;
     Echo "<tr><td colspan=\"8\">&nbsp;</td></tr>" ;
     For ($i = 0 ; $i < $nbr_champs ; $i++)
      {
       $r = SQL_tableau_associatif ($resultats, "") ;
       If ($type_moyenne == 1)
        {
	 $min = (integer)$r ["min"]."%" ;
	 $max = (integer)$r ["max"]."%" ;
	}
       Else
        {
	 $min = Str_Replace (".", ",", $r ["min"]) ;
	 $max = Str_Replace (".", ",", $r ["max"]) ;
	}
       Echo "<tr" ; If ($i%2==1) { Echo " bgcolor=\"".$l ["nom"] ; }
       Echo "\"><td> </td>" ;
       Echo "<td><font size=\"".$l ["titre"]."\">&nbsp;Si&nbsp;".$min."&nbsp;" ;
       Switch ($r ["condition_1"])
        {
	 Case 1 : Echo "&lt;" ; Break ;
	 Case 2 : Echo "&lt;=" ; Break ;
	 Case 3 : Echo "=" ; Break ;
	 Case 4 : Echo "&gt;" ; Break ;
	 Case 5 : Echo "&gt;=" ; Break ;
	}
       Echo "</font>&nbsp;</td>" ;
       Echo "<td><font size=\"".$l ["titre"]."\"><b>Note</b></font></td>" ;
       Echo "<td>&nbsp;<font size=\"".$l ["titre"]."\">" ;
       Switch ($r ["condition_2"])
        {
	 Case 1 : Echo "&lt;" ; Break ;
	 Case 2 : Echo "&lt;=" ; Break ;
	 Case 3 : Echo "=" ; Break ;
	 Case 4 : Echo "&gt;" ; Break ;
	 Case 5 : Echo "&gt;=" ; Break ;
	}
       Echo "&nbsp;".$max."&nbsp;alors&nbsp;&eacute;crire&nbsp;le&nbsp;texte&nbsp;</font></td>" ;
       Echo "<td><font size=\"".$l ["titre"]."\">\"<b>".Str_Replace ("<", "&lt;", Str_Replace (">", "&gt;", $r ["phrase"]))."</b>\"</td>" ;
       Echo "<td><a href=\"./gestion_disciplines_specifiques.php?requete=2&id_phrase_specifique=".$r ["id_phrase_specifique"]."&id_discipline=".$id_discipline."\" border=\"0\"><img src=\"../images/edition.png\" border=\"0\"></a></td>" ;
       Echo "<td><a href=\"./gestion_disciplines_specifiques.php?requete=1&id_phrase_specifique=".$r ["id_phrase_specifique"]."&id_discipline=".$id_discipline."\" border=\"0\"><img src=\"../images/effacer.png\" border=\"0\"></a></td>" ;
       Echo "<td> </td>" ;
       Echo "</tr>" ;
      }
     Echo "<tr><td colspan=\"8\">&nbsp;</td></tr>" ;
    }
   Else
    {
     Echo "<tr><td align=\"center\"><font size=\"".$l ["titre"]."\">&nbsp;<br>&nbsp;Aucune&nbsp;d&eacute;finition&nbsp;&nbsp;actuellement.</b>&nbsp;<br>&nbsp;</font></td></tr>" ;
    }
   Echo "</table></td></tr>" ;
   
   $type_moyenne = champ_disc_type_moyenne_parid ($id_discipline) ;
   If ($type_moyenne == 1) { $min = 0 ; $max = 100 ; $pas = 1 ; } Else { $min = 0 ; $max = $note_par_defaut ; $pas = 0.01 ; }
   Echo "<tr><td align=\"center\" bgcolor=\"".$l ["lien"]."\"><font size=\"".$l ["titre"]."\">&nbsp;<b>Ajouter&nbsp;une&nbsp;nouvelle&nbsp;d&eacute;finition.</b>&nbsp;</font></td></tr>" ;
   Echo "<tr><td align=\"center\">" ;
   Echo "<br>Attention : Lors de l'&eacute;criture des d&eacute;finitions, le syst&egrave;me ne v&eacute;rifie pas encore les superpositionnements.<br>&nbsp;" ;
   $resultats = SQL_commande ("SELECT * FROM champs ORDER BY code_champ", $id_sql) ;
   $nbr_champs = SQL_nbr_lignes ($resultats) ;
   If ($nbr_champs > 0)
    {
     Echo "<br>Vous pouvez utiliser des champs de publipostage ci-dessous :<br><br>" ;
     Echo "<table width=\"100%\" border=\"0\" style=\"border-collapse:collapse\">" ;
     For ($i = 0 ; $i < $nbr_champs ; $i++)
      {
       $r = SQL_tableau_associatif ($resultats, "") ;
       Echo "<tr><td align=\"right\"><b>".Str_Replace ("<", "&lt;", Str_Replace (">", "&gt;", $r ["code_champ"]))."</b>&nbsp;:&nbsp;</td><td>".$r ["commentaire"]."</td></tr>" ;
      }
     Echo "</table><br>&nbsp;" ;
    }
   Echo "<form method=\"post\" action=\"./gestion_disciplines_specifiques.php\" name=\"ajout\">" ;
   Echo "<table align=\"center\" border=\"0\" width=\"100%\" style=\"border-collapse:collapse\">" ;
   Echo "<tr>" ;
   Echo "<td><select name=\"min\">" ;
   For ($i = $min ; $i <= $max ; $i+=$pas)
    {
     Echo "<option value=\"".$i."\">".$i ; If ($type_moyenne == 1) { Echo "%" ; }
     Echo "</option>" ;
    }
   Echo "</select></td>" ;
   Echo "<td><select name=\"condition_1\">" ;
   Echo "<option value=\"1\">&lt;</option><option value=\"2\" selected>&lt;=</option>" ;
   Echo "<option value=\"3\">=</option><option value=\"4\">&gt;</option>" ;
   Echo "<option value=\"5\">&gt;=</option>" ;
   Echo "</select></td>" ;
   Echo "<td>&nbsp;<b>Note</b>&nbsp;</td>" ;
   Echo "<td><select name=\"condition_2\">" ;
   Echo "<option value=\"1\">&lt;</option><option value=\"2\" selected>&lt;=</option>" ;
   Echo "<option value=\"3\">=</option><option value=\"4\">&gt;</option>" ;
   Echo "<option value=\"5\">&gt;=</option>" ;
   Echo "</select></td>" ;
   Echo "<td><select name=\"max\">" ;
   For ($i = $min ; $i <= $max ; $i+=$pas)
    {
     Echo "<option value=\"".$i."\"" ; If ($i == $max) { Echo " selected" ; }
     Echo ">".$i ; If ($type_moyenne == 1) { Echo "%" ; }
     Echo "</option>" ;
    }
   Echo "</select></td>" ;
   Echo "<td>&nbsp;alors&nbsp;&eacute;crire&nbsp;l'appr&eacute;ciation&nbsp;</td>" ;
   Echo "<td><input type=\"text\" name=\"phrase\" value=\"<NOTE_ELEVE>% des items du <NOM_DISCIPLINE_LONG> a ete acquis.\" size=\"50\"></td>" ;
   Echo "<td align=\"right\"colspan=\"6\">" ;
   Echo "<input type=\"hidden\" name=\"code\" VALUE=\"".$_SESSION ["code"]."\">" ;
   Echo "<input type=\"hidden\" name=\"id_discipline\" VALUE=\"".$id_discipline."\">" ;
   Echo "<input type=\"hidden\" name=\"requete\" VALUE=\"0\">" ;
   Echo "<input type=\"image\" src=\"../images/ajouter.png\" alt=\"Ajouter une d&eacute;finition.\" value=\"ajouter\" border=\"0\">" ;
   Echo "</td>" ;
   Echo "</tr>" ;
   Echo "<tr><td colspan=\"8\">&nbsp;</td></tr>" ;
   Echo "</table>" ;
   Echo "</form>" ;
   Echo "</td></tr></table>" ;
   
   // Bouton annuler
   Echo "<form action=\"./gestion_disciplines.php\" method=\"post\">" ;
   Echo "<center><input type=\"image\" src=\"../images/annuler.png\" title=\"Retour aux disciplines...\" border=\"0\"></center>" ;
   Echo "</form>" ;
  }
 Else
  {
   // Probleme d'acces !
  } 
 Echo "</body></html>" ;
?>